Clover icon

compiler

  1. Project Clover database Thu Jan 12 2023 14:04:05 MST
  2. Package com.google.javascript.jscomp

File CompilerOptions.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
87% of files have more coverage

Code metrics

16
411
216
10
2,188
1,117
238
0.58
1.9
21.6
1.1

Classes

Class Line # Actions
CompilerOptions 40 399 226 348
0.437802943.8%
CompilerOptions.Reach 47 0 0 0
-1.0 -
CompilerOptions.LanguageMode 2021 7 7 2
0.8571428785.7%
CompilerOptions.DevMode 2053 0 0 0
-1.0 -
CompilerOptions.TracerMode 2075 1 1 0
1.0100%
CompilerOptions.TweakProcessing 2086 2 2 0
1.0100%
CompilerOptions.AliasTransformationHandler 2113 0 0 0
-1.0 -
CompilerOptions.AliasTransformation 2144 0 0 0
-1.0 -
CompilerOptions.NullAliasTransformationHandler 2165 2 1 0
1.0100%
CompilerOptions.NullAliasTransformationHandler.NullAliasTransformation 2179 0 1 0
1.0100%
 

Contributing tests

This file is covered by 1936 tests. .

Source view

1    /*
2    * Copyright 2009 The Closure Compiler Authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package com.google.javascript.jscomp;
18   
19    import com.google.common.base.Preconditions;
20    import com.google.common.collect.Lists;
21    import com.google.common.collect.Maps;
22    import com.google.common.collect.Multimap;
23    import com.google.common.collect.Sets;
24    import com.google.javascript.rhino.IR;
25    import com.google.javascript.rhino.Node;
26    import com.google.javascript.rhino.SourcePosition;
27   
28    import java.io.Serializable;
29    import java.nio.charset.Charset;
30    import java.text.ParseException;
31    import java.util.Collections;
32    import java.util.List;
33    import java.util.Map;
34    import java.util.Set;
35   
36    /**
37    * Compiler options
38    * @author nicksantos@google.com (Nick Santos)
39    */
 
40    public class CompilerOptions implements Serializable, Cloneable {
41   
42    // Unused. For people using reflection to circumvent access control.
43    @SuppressWarnings("unused")
44    private boolean manageClosureDependencies = false;
45   
46    // A common enum for compiler passes that can run either globally or locally.
 
47    public enum Reach {
48    ALL,
49    LOCAL_ONLY,
50    NONE
51    }
52   
53    // TODO(nicksantos): All public properties of this class should be made
54    // package-private, and have a public setter.
55   
56    private static final long serialVersionUID = 7L;
57   
58    /**
59    * The JavaScript language version accepted.
60    */
61    private LanguageMode languageIn;
62   
63    /**
64    * The JavaScript language version that should be produced.
65    * Currently, this is always the same as {@link #languageIn}.
66    */
67    private LanguageMode languageOut;
68   
69    /**
70    * Whether the compiler accepts the `const' keyword.
71    */
72    boolean acceptConstKeyword;
73   
74    /**
75    * Whether the compiler should assume that a function's "this" value
76    * never needs coercion (for example in non-strict "null" or "undefined" will
77    * be coerced to the global "this" and primitives to objects).
78    */
79    private boolean assumeStrictThis;
80   
81    /**
82    * Configures the compiler for use as an IDE backend. In this mode:
83    * <ul>
84    * <li>No optimization passes will run.</li>
85    * <li>The last time custom passes are invoked is
86    * {@link CustomPassExecutionTime#BEFORE_OPTIMIZATIONS}</li>
87    * <li>The compiler will always try to process all inputs fully, even
88    * if it encounters errors.</li>
89    * <li>The compiler may record more information than is strictly
90    * needed for codegen.</li>
91    * </ul>
92    */
93    public boolean ideMode;
94   
95    boolean saveDataStructures = false;
96   
97    /**
98    * Even if checkTypes is disabled, clients might want to still infer types.
99    * This is mostly used when ideMode is enabled.
100    */
101    boolean inferTypes;
102   
103    /**
104    * Configures the compiler to skip as many passes as possible.
105    */
106    boolean skipAllPasses;
107   
108    /**
109    * If true, name anonymous functions only. All others passes will be skipped.
110    */
111    boolean nameAnonymousFunctionsOnly;
112   
113    /**
114    * Configures the compiler to run expensive sanity checks after
115    * every pass. Only intended for internal development.
116    */
117    DevMode devMode;
118   
119    //--------------------------------
120    // Input Options
121    //--------------------------------
122   
123    DependencyOptions dependencyOptions = new DependencyOptions();
124   
125    /** Returns localized replacement for MSG_* variables */
126    // Transient so that clients don't have to implement Serializable.
127    public transient MessageBundle messageBundle = null;
128   
129    //--------------------------------
130    // Checks
131    //--------------------------------
132   
133    /** Checks that all symbols are defined */
134    public boolean checkSymbols;
135   
136    public CheckLevel aggressiveVarCheck;
137   
138    /** Checks for suspicious variable definitions and undefined variables */
 
139  0 toggle public void setAggressiveVarCheck(CheckLevel level) {
140  0 this.aggressiveVarCheck = level;
141    }
142   
143    /** Checks for suspicious statements that have no effect */
144    public boolean checkSuspiciousCode;
145   
146    /** Checks for invalid control structures */
147    public boolean checkControlStructures;
148   
149    /** Checks types on expressions */
150    public boolean checkTypes;
151   
152    boolean tightenTypes;
153   
154    /** Tightens types based on a global analysis. Experimental. */
 
155  0 toggle public void setTightenTypes(boolean tighten) {
156  0 tightenTypes = tighten;
157    }
158   
159    public CheckLevel reportMissingOverride;
160   
161    /**
162    * Flags a warning if a property is missing the @override annotation, but it
163    * overrides a base class property.
164    */
 
165  0 toggle public void setReportMissingOverride(CheckLevel level) {
166  0 reportMissingOverride = level;
167    }
168   
169    CheckLevel reportUnknownTypes;
170   
171    /** Flags a warning for every node whose type could not be determined. */
 
172  0 toggle public void setReportUnknownTypes(CheckLevel level) {
173  0 reportUnknownTypes = level;
174    }
175   
176    /** Checks for missing goog.require() calls **/
177    public CheckLevel checkRequires;
178   
 
179  0 toggle public void setCheckRequires(CheckLevel level) {
180  0 checkRequires = level;
181    }
182   
183    public CheckLevel checkProvides;
184   
185    /** Checks for missing goog.provides() calls **/
 
186  2 toggle public void setCheckProvides(CheckLevel level) {
187  2 checkProvides = level;
188    }
189   
190    public CheckLevel checkGlobalNamesLevel;
191   
192    /**
193    * Checks the integrity of references to qualified global names.
194    * (e.g. "a.b")
195    */
 
196  0 toggle public void setCheckGlobalNamesLevel(CheckLevel level) {
197  0 checkGlobalNamesLevel = level;
198    }
199   
200    public CheckLevel brokenClosureRequiresLevel;
201   
202    /** Sets the check level for bad Closure require calls. */
 
203  0 toggle public void setBrokenClosureRequiresLevel(CheckLevel level) {
204  0 brokenClosureRequiresLevel = level;
205    }
206   
207    public CheckLevel checkGlobalThisLevel;
208   
209    /**
210    * Checks for certain uses of the {@code this} keyword that are considered
211    * unsafe because they are likely to reference the global {@code this}
212    * object unintentionally.
213    *
214    * If this is off, but collapseProperties is on, then the compiler will
215    * usually ignore you and run this check anyways.
216    */
 
217  0 toggle public void setCheckGlobalThisLevel(CheckLevel level) {
218  0 this.checkGlobalThisLevel = level;
219    }
220   
221    public CheckLevel checkMissingGetCssNameLevel;
222   
223    /**
224    * Checks that certain string literals only appear in strings used as
225    * goog.getCssName arguments.
226    */
 
227  0 toggle public void setCheckMissingGetCssNameLevel(CheckLevel level) {
228  0 this.checkMissingGetCssNameLevel = level;
229    }
230   
231    /**
232    * Regex of string literals that may only appear in goog.getCssName arguments.
233    */
234    public String checkMissingGetCssNameBlacklist;
235   
236    /** Checks that the syntactic restrictions of Caja are met. */
237    boolean checkCaja;
238   
 
239  0 toggle public void setCheckCaja(boolean check) {
240  0 checkCaja = check;
241    }
242   
243    /**
244    * A set of extra annotation names which are accepted and silently ignored
245    * when encountered in a source file. Defaults to null which has the same
246    * effect as specifying an empty set.
247    */
248    Set<String> extraAnnotationNames;
249   
250    //--------------------------------
251    // Optimizations
252    //--------------------------------
253   
254    /** Folds constants (e.g. (2 + 3) to 5) */
255    public boolean foldConstants;
256   
257    /** Remove assignments to values that can not be referenced */
258    public boolean deadAssignmentElimination;
259   
260    /** Inlines constants (symbols that are all CAPS) */
261    public boolean inlineConstantVars;
262   
263    /** Inlines global functions */
264    public boolean inlineFunctions;
265   
266    /** Inlines functions defined in local scopes */
267    public boolean inlineLocalFunctions;
268   
269    /** Inlines properties */
270    boolean inlineProperties;
271   
272    /** Move code to a deeper module */
273    public boolean crossModuleCodeMotion;
274   
275    /** Merge two variables together as one. */
276    public boolean coalesceVariableNames;
277   
278    /** Move methods to a deeper module */
279    public boolean crossModuleMethodMotion;
280   
281    /** Inlines trivial getters */
282    public boolean inlineGetters;
283   
284    /** Inlines variables */
285    public boolean inlineVariables;
286   
287    /** Inlines variables */
288    boolean inlineLocalVariables;
289   
290    // TODO(user): This is temporary. Once flow sensitive inlining is stable
291    // Remove this.
292    public boolean flowSensitiveInlineVariables;
293   
294    /** Removes code associated with unused global names */
295    public boolean smartNameRemoval;
296   
297    /** Removes code that will never execute */
298    public boolean removeDeadCode;
299   
300    public CheckLevel checkUnreachableCode;
301   
302    /** Checks for unreachable code */
 
303  0 toggle public void setCheckUnreachableCode(CheckLevel level) {
304  0 this.checkUnreachableCode = level;
305    }
306   
307    public CheckLevel checkMissingReturn;
308   
309    /** Checks for missing return statements */
 
310  0 toggle public void setCheckMissingReturn(CheckLevel level) {
311  0 this.checkMissingReturn = level;
312    }
313   
314    /** Extracts common prototype member declarations */
315    public boolean extractPrototypeMemberDeclarations;
316   
317    /** Removes unused member prototypes */
318    public boolean removeUnusedPrototypeProperties;
319   
320    /** Tells AnalyzePrototypeProperties it can remove externed props. */
321    public boolean removeUnusedPrototypePropertiesInExterns;
322   
323    /** Removes unused member properties */
324    public boolean removeUnusedClassProperties;
325   
326    /** Removes unused variables */
327    public boolean removeUnusedVars;
328   
329    /** Removes unused variables in local scope. */
330    public boolean removeUnusedLocalVars;
331   
332    /** Adds variable aliases for externals to reduce code size */
333    public boolean aliasExternals;
334   
335    String aliasableGlobals;
336   
337    /**
338    * A comma separated white-list of global names. When {@link #aliasExternals}
339    * is enable, if set to a non-empty string, only externals with these names
340    * will be considered for aliasing.
341    */
 
342  0 toggle public void setAliasableGlobals(String names) {
343  0 aliasableGlobals = names;
344    }
345   
346    String unaliasableGlobals;
347   
348    /**
349    * A comma separated white-list of global names. When {@link #aliasExternals}
350    * is enable, these global names will not be aliased.
351    */
 
352  0 toggle public void setUnaliasableGlobals(String names) {
353  0 unaliasableGlobals = names;
354    }
355   
356    /** Collapses multiple variable declarations into one */
357    public boolean collapseVariableDeclarations;
358   
359    /** Group multiple variable declarations into one */
360    boolean groupVariableDeclarations;
361   
362    /**
363    * Collapses anonymous function declarations into named function
364    * declarations
365    */
366    public boolean collapseAnonymousFunctions;
367   
368    /**
369    * If set to a non-empty set, those strings literals will be aliased to a
370    * single global instance per string, to avoid creating more objects than
371    * necessary.
372    */
373    public Set<String> aliasableStrings;
374   
375    /**
376    * A blacklist in the form of a regular expression to block strings that
377    * contains certain words from being aliased.
378    * If the value is the empty string, no words are blacklisted.
379    */
380    public String aliasStringsBlacklist;
381   
382    /**
383    * Aliases all string literals to global instances, to avoid creating more
384    * objects than necessary (if true, overrides any set of strings passed in
385    * to aliasableStrings)
386    */
387    public boolean aliasAllStrings;
388   
389    /** Print string usage as part of the compilation log. */
390    boolean outputJsStringUsage;
391   
392    /** Converts quoted property accesses to dot syntax (a['b'] -> a.b) */
393    public boolean convertToDottedProperties;
394   
395    /** Reduces the size of common function expressions. */
396    public boolean rewriteFunctionExpressions;
397   
398    /**
399    * Remove unused and constant parameters.
400    */
401    public boolean optimizeParameters;
402   
403    /**
404    * Remove unused return values.
405    */
406    public boolean optimizeReturns;
407   
408    /**
409    * Remove unused parameters from call sites.
410    */
411    public boolean optimizeCalls;
412   
413    /**
414    * Provide formal names for elements of arguments array.
415    */
416    public boolean optimizeArgumentsArray;
417   
418    /** Chains calls to functions that return this. */
419    boolean chainCalls;
420   
421    //--------------------------------
422    // Renaming
423    //--------------------------------
424   
425    /** Controls which variables get renamed. */
426    public VariableRenamingPolicy variableRenaming;
427   
428    /** Controls which properties get renamed. */
429    public PropertyRenamingPolicy propertyRenaming;
430   
431    /** Should we use affinity information when generating property names. */
432    boolean propertyAffinity;
433   
434    /** Controls label renaming. */
435    public boolean labelRenaming;
436   
437    /** Reserve property names on the global this object. */
438    public boolean reserveRawExports;
439   
440    /** Should shadow variable names in outer scope. */
441    boolean shadowVariables;
442   
443    /**
444    * Generate pseudo names for variables and properties for debugging purposes.
445    */
446    public boolean generatePseudoNames;
447   
448    /** Specifies a prefix for all globals */
449    public String renamePrefix;
450   
451    /**
452    * Specifies the name of an object that will be used to store all non-extern
453    * globals.
454    */
455    public String renamePrefixNamespace;
456   
457    /** Aliases true, false, and null to variables with shorter names. */
458    public boolean aliasKeywords;
459   
460    /** Flattens multi-level property names (e.g. a$b = x) */
461    public boolean collapseProperties;
462   
463    /** Split object literals into individual variables when possible. */
464    boolean collapseObjectLiterals;
465   
 
466  0 toggle public void setCollapseObjectLiterals(boolean enabled) {
467  0 collapseObjectLiterals = enabled;
468    }
469   
470    /** Flattens multi-level property names on extern types (e.g. String$f = x) */
471    boolean collapsePropertiesOnExternTypes;
472   
473    /**
474    * Devirtualize prototype method by rewriting them to be static calls that
475    * take the this pointer as their first argument
476    */
477    public boolean devirtualizePrototypeMethods;
478   
479    /**
480    * Use @nosideeffects annotations, function bodies and name graph
481    * to determine if calls have side effects. Requires --check_types.
482    */
483    public boolean computeFunctionSideEffects;
484   
485    /**
486    * Where to save debug report for compute function side effects.
487    */
488    String debugFunctionSideEffectsPath;
489   
490    /**
491    * Rename properties to disambiguate between unrelated fields based on
492    * type information.
493    */
494    public boolean disambiguateProperties;
495   
496    /** Rename unrelated properties to the same name to reduce code size. */
497    public boolean ambiguateProperties;
498   
499    /** Give anonymous functions names for easier debugging */
500    public AnonymousFunctionNamingPolicy anonymousFunctionNaming;
501   
502    /** Input anonymous function renaming map. */
503    VariableMap inputAnonymousFunctionNamingMap;
504   
505    /** Input variable renaming map. */
506    VariableMap inputVariableMap;
507   
508    /** Input property renaming map. */
509    VariableMap inputPropertyMap;
510   
511    /** Whether to export test functions. */
512    public boolean exportTestFunctions;
513   
514    boolean specializeInitialModule;
515   
516    /** Specialize the initial module at the cost of later modules */
 
517  0 toggle public void setSpecializeInitialModule(boolean enabled) {
518  0 specializeInitialModule = enabled;
519    }
520   
521    //--------------------------------
522    // Special-purpose alterations
523    //--------------------------------
524   
525    /**
526    * Replace UI strings with chrome.i18n.getMessage calls.
527    * Used by Chrome extensions/apps.
528    */
529    boolean replaceMessagesWithChromeI18n;
530    String tcProjectId;
531   
 
532  0 toggle public void setReplaceMessagesWithChromeI18n(
533    boolean replaceMessagesWithChromeI18n,
534    String tcProjectId) {
535  0 if (replaceMessagesWithChromeI18n &&
536    messageBundle != null &&
537    !(messageBundle instanceof EmptyMessageBundle)) {
538  0 throw new RuntimeException("When replacing messages with " +
539    "chrome.i18n.getMessage, a message bundle should not be specified.");
540    }
541   
542  0 this.replaceMessagesWithChromeI18n = replaceMessagesWithChromeI18n;
543  0 this.tcProjectId = tcProjectId;
544    }
545   
546    /** Inserts run-time type assertions for debugging. */
547    boolean runtimeTypeCheck;
548   
549    /**
550    * A JS function to be used for logging run-time type assertion
551    * failures. It will be passed the warning as a string and the
552    * faulty expression as arguments.
553    */
554    String runtimeTypeCheckLogFunction;
555   
556    /** A CodingConvention to use during the compile. */
557    private CodingConvention codingConvention;
558   
559    boolean ignoreCajaProperties;
560   
561    /** Add code to skip properties that Caja adds to Object.prototype */
 
562  0 toggle public void setIgnoreCajaProperties(boolean enabled) {
563  0 ignoreCajaProperties = enabled;
564    }
565   
566    public String syntheticBlockStartMarker;
567   
568    public String syntheticBlockEndMarker;
569   
570    /** Compiling locale */
571    public String locale;
572   
573    /** Sets the special "COMPILED" value to true */
574    public boolean markAsCompiled;
575   
576    /** Removes try...catch...finally blocks for easier debugging */
577    public boolean removeTryCatchFinally;
578   
579    /** Processes goog.provide() and goog.require() calls */
580    public boolean closurePass;
581   
582    /** Processes jQuery aliases */
583    public boolean jqueryPass;
584   
585    /** Remove goog.abstractMethod assignments. */
586    boolean removeAbstractMethods;
587   
588    /** Remove goog.asserts calls. */
589    boolean removeClosureAsserts;
590   
591    /** Gather CSS names (requires closurePass) */
592    public boolean gatherCssNames;
593   
594    /** Names of types to strip */
595    public Set<String> stripTypes;
596   
597    /** Name suffixes that determine which variables and properties to strip */
598    public Set<String> stripNameSuffixes;
599   
600    /** Name prefixes that determine which variables and properties to strip */
601    public Set<String> stripNamePrefixes;
602   
603    /** Qualified type name prefixes that determine which types to strip */
604    public Set<String> stripTypePrefixes;
605   
606    /** Custom passes */
607    public transient
608    Multimap<CustomPassExecutionTime, CompilerPass> customPasses;
609   
610    /** Mark no side effect calls */
611    public boolean markNoSideEffectCalls;
612   
613    /** Replacements for @defines. Will be Boolean, Numbers, or Strings */
614    private Map<String, Object> defineReplacements;
615   
616    /** What kind of processing to do for goog.tweak functions. */
617    private TweakProcessing tweakProcessing;
618   
619    /** Replacements for tweaks. Will be Boolean, Numbers, or Strings */
620    private Map<String, Object> tweakReplacements;
621   
622    /** Move top-level function declarations to the top */
623    public boolean moveFunctionDeclarations;
624   
625    /** Instrumentation template to use with #recordFunctionInformation */
626    public String instrumentationTemplate;
627   
628    String appNameStr;
629   
630    /**
631    * App identifier string for use by the instrumentation template's
632    * app_name_setter. @see #instrumentationTemplate
633    */
 
634  0 toggle public void setAppNameStr(String appNameStr) {
635  0 this.appNameStr = appNameStr;
636    }
637   
638    /** Record function information */
639    public boolean recordFunctionInformation;
640   
641    public boolean generateExports;
642   
643    /** Map used in the renaming of CSS class names. */
644    public CssRenamingMap cssRenamingMap;
645   
646    /** Whitelist used in the renaming of CSS class names. */
647    Set<String> cssRenamingWhitelist;
648   
649    /** Process instances of goog.testing.ObjectPropertyString. */
650    boolean processObjectPropertyString;
651   
652    /** Replace id generators */
653    boolean replaceIdGenerators = true; // true by default for legacy reasons.
654   
655    /** Id generators to replace. */
656    Set<String> idGenerators;
657   
658    /**
659    * A previous map of ids (serialized to a string by a previous compile).
660    * This will be used as a hint during the ReplaceIdGenerators pass, which
661    * will attempt to reuse the same ids.
662    */
663    String idGeneratorsMapSerialized;
664   
665    /** Configuration strings */
666    List<String> replaceStringsFunctionDescriptions;
667   
668    String replaceStringsPlaceholderToken;
669    // A list of strings that should not be used as replacements
670    Set<String> replaceStringsReservedStrings;
671    // A previous map of replacements to strings.
672    VariableMap replaceStringsInputMap;
673   
674    /** List of properties that we report invalidation errors for. */
675    Map<String, CheckLevel> propertyInvalidationErrors;
676   
677    /** Transform AMD to CommonJS modules. */
678    boolean transformAMDToCJSModules = false;
679   
680    /** Rewrite CommonJS modules so that they can be concatenated together. */
681    boolean processCommonJSModules = false;
682   
683    /** CommonJS module prefix. */
684    String commonJSModulePathPrefix =
685    ProcessCommonJSModules.DEFAULT_FILENAME_PREFIX;
686   
687   
688    //--------------------------------
689    // Output options
690    //--------------------------------
691   
692    /** Output in pretty indented format */
693    public boolean prettyPrint;
694   
695    /** Line break the output a bit more aggressively */
696    public boolean lineBreak;
697   
698    /** Prefer line breaks at end of file */
699    public boolean preferLineBreakAtEndOfFile;
700   
701    /** Prints a separator comment before each JS script */
702    public boolean printInputDelimiter;
703   
704    /** The string to use as the separator for printInputDelimiter */
705    public String inputDelimiter = "// Input %num%";
706   
707    boolean preferSingleQuotes;
708   
709    /**
710    * Normally, when there are an equal number of single and double quotes
711    * in a string, the compiler will use double quotes. Set this to true
712    * to prefer single quotes.
713    */
 
714  1 toggle public void setPreferSingleQuotes(boolean enabled) {
715  1 this.preferSingleQuotes = enabled;
716    }
717   
718    boolean trustedStrings;
719   
720    /**
721    * Some people want to put arbitrary user input into strings, which are then
722    * run through the compiler. These scripts are then put into HTML.
723    * By default, we assume strings are untrusted. If the compiler is run
724    * from the command-line, we assume that strings are trusted.
725    */
 
726  874 toggle public void setTrustedStrings(boolean yes) {
727  874 trustedStrings = yes;
728    }
729   
730    String reportPath;
731   
732    /** Where to save a report of global name usage */
 
733  0 toggle public void setReportPath(String reportPath) {
734  0 this.reportPath = reportPath;
735    }
736   
737    TracerMode tracer;
738   
 
739  0 toggle public TracerMode getTracerMode() {
740  0 return tracer;
741    }
742   
 
743  0 toggle public void setTracerMode(TracerMode mode) {
744  0 tracer = mode;
745    }
746   
747    private boolean colorizeErrorOutput;
748   
749    public ErrorFormat errorFormat;
750   
751    private ComposeWarningsGuard warningsGuard = new ComposeWarningsGuard();
752   
753    int summaryDetailLevel = 1;
754   
755    int lineLengthThreshold = CodePrinter.DEFAULT_LINE_LENGTH_THRESHOLD;
756   
757    //--------------------------------
758    // Special Output Options
759    //--------------------------------
760   
761    /**
762    * Whether the exports should be made available via {@link Result} after
763    * compilation. This is implicitly true if {@link #externExportsPath} is set.
764    */
765    private boolean externExports;
766   
767    /** The output path for the created externs file. */
768    String externExportsPath;
769   
770    String nameReferenceReportPath;
771   
772    /** Where to save a cross-reference report from the name reference graph */
 
773  0 toggle public void setNameReferenceReportPath(String filePath) {
774  0 nameReferenceReportPath = filePath;
775    }
776   
777    String nameReferenceGraphPath;
778   
779    /** Where to save the name reference graph */
 
780  0 toggle public void setNameReferenceGraphPath(String filePath) {
781  0 nameReferenceGraphPath = filePath;
782    }
783   
784    //--------------------------------
785    // Debugging Options
786    //--------------------------------
787   
788    /** The output path for the source map. */
789    public String sourceMapOutputPath;
790   
791    /** The detail level for the generated source map. */
792    public SourceMap.DetailLevel sourceMapDetailLevel =
793    SourceMap.DetailLevel.SYMBOLS;
794   
795    /** The source map file format */
796    public SourceMap.Format sourceMapFormat =
797    SourceMap.Format.DEFAULT;
798   
799    public List<SourceMap.LocationMapping> sourceMapLocationMappings =
800    Collections.emptyList();
801   
802    /**
803    * Charset to use when generating code. If null, then output ASCII.
804    * This needs to be a string because CompilerOptions is serializable.
805    */
806    String outputCharset;
807   
808    /**
809    * Whether the named objects types included 'undefined' by default.
810    */
811    boolean looseTypes;
812   
813    /**
814    * When set, assume that apparently side-effect free code is meaningful.
815    */
816    boolean protectHiddenSideEffects;
817   
818    /**
819    * When enabled, assume that apparently side-effect free code is meaningful.
820    */
 
821  0 toggle public void setProtectHiddenSideEffects(boolean enable) {
822  0 this.protectHiddenSideEffects = enable;
823    }
824   
825    /**
826    * Data holder Alias Transformation information accumulated during a compile.
827    */
828    private transient AliasTransformationHandler aliasHandler;
829   
830    /**
831    * Handler for compiler warnings and errors.
832    */
833    transient ErrorHandler errorHandler;
834   
835    /**
836    * Initializes compiler options. All options are disabled by default.
837    *
838    * Command-line frontends to the compiler should set these properties
839    * like a builder.
840    */
 
841  47951 toggle public CompilerOptions() {
842    // Accepted language
843  47951 languageIn = LanguageMode.ECMASCRIPT3;
844   
845    // Language variation
846  47951 acceptConstKeyword = false;
847   
848    // Checks
849  47951 skipAllPasses = false;
850  47951 nameAnonymousFunctionsOnly = false;
851  47951 devMode = DevMode.OFF;
852  47951 checkSymbols = false;
853  47951 aggressiveVarCheck = CheckLevel.OFF;
854  47951 checkSuspiciousCode = false;
855  47951 checkControlStructures = false;
856  47951 checkTypes = false;
857  47951 tightenTypes = false;
858  47951 reportMissingOverride = CheckLevel.OFF;
859  47951 reportUnknownTypes = CheckLevel.OFF;
860  47951 checkRequires = CheckLevel.OFF;
861  47951 checkProvides = CheckLevel.OFF;
862  47951 checkGlobalNamesLevel = CheckLevel.OFF;
863  47951 brokenClosureRequiresLevel = CheckLevel.ERROR;
864  47951 checkGlobalThisLevel = CheckLevel.OFF;
865  47951 checkUnreachableCode = CheckLevel.OFF;
866  47951 checkMissingReturn = CheckLevel.OFF;
867  47951 checkMissingGetCssNameLevel = CheckLevel.OFF;
868  47951 checkMissingGetCssNameBlacklist = null;
869  47951 checkCaja = false;
870  47951 computeFunctionSideEffects = false;
871  47951 chainCalls = false;
872  47951 extraAnnotationNames = null;
873   
874    // Optimizations
875  47951 foldConstants = false;
876  47951 coalesceVariableNames = false;
877  47951 deadAssignmentElimination = false;
878  47951 inlineConstantVars = false;
879  47951 inlineFunctions = false;
880  47951 inlineLocalFunctions = false;
881  47951 assumeStrictThis = false;
882  47951 inlineProperties = false;
883  47951 crossModuleCodeMotion = false;
884  47951 crossModuleMethodMotion = false;
885  47951 inlineGetters = false;
886  47951 inlineVariables = false;
887  47951 inlineLocalVariables = false;
888  47951 smartNameRemoval = false;
889  47951 removeDeadCode = false;
890  47951 extractPrototypeMemberDeclarations = false;
891  47951 removeUnusedPrototypeProperties = false;
892  47951 removeUnusedPrototypePropertiesInExterns = false;
893  47951 removeUnusedClassProperties = false;
894  47951 removeUnusedVars = false;
895  47951 removeUnusedLocalVars = false;
896  47951 aliasExternals = false;
897  47951 collapseVariableDeclarations = false;
898  47951 groupVariableDeclarations = false;
899  47951 collapseAnonymousFunctions = false;
900  47951 aliasableStrings = Collections.emptySet();
901  47951 aliasStringsBlacklist = "";
902  47951 aliasAllStrings = false;
903  47951 outputJsStringUsage = false;
904  47951 convertToDottedProperties = false;
905  47951 rewriteFunctionExpressions = false;
906  47951 optimizeParameters = false;
907  47951 optimizeReturns = false;
908   
909    // Renaming
910  47951 variableRenaming = VariableRenamingPolicy.OFF;
911  47951 propertyRenaming = PropertyRenamingPolicy.OFF;
912  47951 propertyAffinity = false;
913  47951 labelRenaming = false;
914  47951 generatePseudoNames = false;
915  47951 shadowVariables = false;
916  47951 renamePrefix = null;
917  47951 aliasKeywords = false;
918  47951 collapseProperties = false;
919  47951 collapsePropertiesOnExternTypes = false;
920  47951 collapseObjectLiterals = false;
921  47951 devirtualizePrototypeMethods = false;
922  47951 disambiguateProperties = false;
923  47951 ambiguateProperties = false;
924  47951 anonymousFunctionNaming = AnonymousFunctionNamingPolicy.OFF;
925  47951 exportTestFunctions = false;
926   
927    // Alterations
928  47951 runtimeTypeCheck = false;
929  47951 runtimeTypeCheckLogFunction = null;
930  47951 ignoreCajaProperties = false;
931  47951 syntheticBlockStartMarker = null;
932  47951 syntheticBlockEndMarker = null;
933  47951 locale = null;
934  47951 markAsCompiled = false;
935  47951 removeTryCatchFinally = false;
936  47951 closurePass = false;
937  47951 jqueryPass = false;
938  47951 removeAbstractMethods = true;
939  47951 removeClosureAsserts = false;
940  47951 stripTypes = Collections.emptySet();
941  47951 stripNameSuffixes = Collections.emptySet();
942  47951 stripNamePrefixes = Collections.emptySet();
943  47951 stripTypePrefixes = Collections.emptySet();
944  47951 customPasses = null;
945  47951 markNoSideEffectCalls = false;
946  47951 defineReplacements = Maps.newHashMap();
947  47951 tweakProcessing = TweakProcessing.OFF;
948  47951 tweakReplacements = Maps.newHashMap();
949  47951 moveFunctionDeclarations = false;
950  47951 instrumentationTemplate = null;
951  47951 appNameStr = "";
952  47951 recordFunctionInformation = false;
953  47951 generateExports = false;
954  47951 cssRenamingMap = null;
955  47951 cssRenamingWhitelist = null;
956  47951 processObjectPropertyString = false;
957  47951 idGenerators = Collections.emptySet();
958  47951 replaceStringsFunctionDescriptions = Collections.emptyList();
959  47951 replaceStringsPlaceholderToken = "";
960  47951 replaceStringsReservedStrings = Collections.emptySet();
961  47951 propertyInvalidationErrors = Maps.newHashMap();
962   
963    // Output
964  47951 printInputDelimiter = false;
965  47951 prettyPrint = false;
966  47951 lineBreak = false;
967  47951 preferLineBreakAtEndOfFile = false;
968  47951 reportPath = null;
969  47951 tracer = TracerMode.OFF;
970  47951 colorizeErrorOutput = false;
971  47951 errorFormat = ErrorFormat.SINGLELINE;
972  47951 debugFunctionSideEffectsPath = null;
973  47951 externExports = false;
974  47951 nameReferenceReportPath = null;
975  47951 nameReferenceGraphPath = null;
976   
977    // Debugging
978  47951 aliasHandler = NULL_ALIAS_TRANSFORMATION_HANDLER;
979  47951 errorHandler = null;
980    }
981   
982    /**
983    * @return Whether to attempt to remove unused class properties
984    */
 
985  0 toggle public boolean isRemoveUnusedClassProperties() {
986  0 return removeUnusedClassProperties;
987    }
988   
989    /**
990    * @param removeUnusedClassProperties Whether to attempt to remove
991    * unused class properties
992    */
 
993  0 toggle public void setRemoveUnusedClassProperties(boolean removeUnusedClassProperties) {
994  0 this.removeUnusedClassProperties = removeUnusedClassProperties;
995    }
996   
997    /**
998    * Returns the map of define replacements.
999    */
 
1000  230 toggle public Map<String, Node> getDefineReplacements() {
1001  230 return getReplacementsHelper(defineReplacements);
1002    }
1003   
1004    /**
1005    * Returns the map of tweak replacements.
1006    */
 
1007  0 toggle public Map<String, Node> getTweakReplacements() {
1008  0 return getReplacementsHelper(tweakReplacements);
1009    }
1010   
1011    /**
1012    * Creates a map of String->Node from a map of String->Number/String/Boolean.
1013    */
 
1014  230 toggle private static Map<String, Node> getReplacementsHelper(
1015    Map<String, Object> source) {
1016  230 Map<String, Node> map = Maps.newHashMap();
1017  230 for (Map.Entry<String, Object> entry : source.entrySet()) {
1018  9 String name = entry.getKey();
1019  9 Object value = entry.getValue();
1020  9 if (value instanceof Boolean) {
1021  5 map.put(name, NodeUtil.booleanNode(((Boolean) value).booleanValue()));
1022  4 } else if (value instanceof Integer) {
1023  1 map.put(name, IR.number(((Integer) value).intValue()));
1024  3 } else if (value instanceof Double) {
1025  1 map.put(name, IR.number(((Double) value).doubleValue()));
1026    } else {
1027  2 Preconditions.checkState(value instanceof String);
1028  2 map.put(name, IR.string((String) value));
1029    }
1030    }
1031  230 return map;
1032    }
1033   
1034    /**
1035    * Sets the value of the {@code @define} variable in JS
1036    * to a boolean literal.
1037    */
 
1038  5 toggle public void setDefineToBooleanLiteral(String defineName, boolean value) {
1039  5 defineReplacements.put(defineName, new Boolean(value));
1040    }
1041   
1042    /**
1043    * Sets the value of the {@code @define} variable in JS to a
1044    * String literal.
1045    */
 
1046  2 toggle public void setDefineToStringLiteral(String defineName, String value) {
1047  2 defineReplacements.put(defineName, value);
1048    }
1049   
1050    /**
1051    * Sets the value of the {@code @define} variable in JS to a
1052    * number literal.
1053    */
 
1054  1 toggle public void setDefineToNumberLiteral(String defineName, int value) {
1055  1 defineReplacements.put(defineName, new Integer(value));
1056    }
1057   
1058    /**
1059    * Sets the value of the {@code @define} variable in JS to a
1060    * number literal.
1061    */
 
1062  1 toggle public void setDefineToDoubleLiteral(String defineName, double value) {
1063  1 defineReplacements.put(defineName, new Double(value));
1064    }
1065   
1066    /**
1067    * Sets the value of the tweak in JS
1068    * to a boolean literal.
1069    */
 
1070  0 toggle public void setTweakToBooleanLiteral(String tweakId, boolean value) {
1071  0 tweakReplacements.put(tweakId, new Boolean(value));
1072    }
1073   
1074    /**
1075    * Sets the value of the tweak in JS to a
1076    * String literal.
1077    */
 
1078  0 toggle public void setTweakToStringLiteral(String tweakId, String value) {
1079  0 tweakReplacements.put(tweakId, value);
1080    }
1081   
1082    /**
1083    * Sets the value of the tweak in JS to a
1084    * number literal.
1085    */
 
1086  0 toggle public void setTweakToNumberLiteral(String tweakId, int value) {
1087  0 tweakReplacements.put(tweakId, new Integer(value));
1088    }
1089   
1090    /**
1091    * Sets the value of the tweak in JS to a
1092    * number literal.
1093    */
 
1094  0 toggle public void setTweakToDoubleLiteral(String tweakId, double value) {
1095  0 tweakReplacements.put(tweakId, new Double(value));
1096    }
1097   
1098    /**
1099    * Skip all possible passes, to make the compiler as fast as possible.
1100    */
 
1101  2 toggle public void skipAllCompilerPasses() {
1102  2 skipAllPasses = true;
1103    }
1104   
1105    /**
1106    * Whether the warnings guard in this Options object enables the given
1107    * group of warnings.
1108    */
 
1109  21401 toggle boolean enables(DiagnosticGroup type) {
1110  21401 return warningsGuard.enables(type);
1111    }
1112   
1113    /**
1114    * Whether the warnings guard in this Options object disables the given
1115    * group of warnings.
1116    */
 
1117  2078 toggle boolean disables(DiagnosticGroup type) {
1118  2078 return warningsGuard.disables(type);
1119    }
1120   
1121    /**
1122    * Configure the given type of warning to the given level.
1123    */
 
1124  38936 toggle public void setWarningLevel(DiagnosticGroup type, CheckLevel level) {
1125  38936 addWarningsGuard(new DiagnosticGroupWarningsGuard(type, level));
1126    }
1127   
 
1128  20399 toggle WarningsGuard getWarningsGuard() {
1129  20399 return warningsGuard;
1130    }
1131   
1132    /**
1133    * Reset the warnings guard.
1134    */
 
1135  0 toggle public void resetWarningsGuard() {
1136  0 warningsGuard = new ComposeWarningsGuard();
1137    }
1138   
1139    /**
1140    * The emergency fail safe removes all strict and ERROR-escalating
1141    * warnings guards.
1142    */
 
1143  1 toggle void useEmergencyFailSafe() {
1144  1 warningsGuard = warningsGuard.makeEmergencyFailSafeGuard();
1145    }
1146   
1147    /**
1148    * Add a guard to the set of warnings guards.
1149    */
 
1150  38940 toggle public void addWarningsGuard(WarningsGuard guard) {
1151  38940 warningsGuard.addGuard(guard);
1152    }
1153   
1154    /**
1155    * Sets the variable and property renaming policies for the compiler,
1156    * in a way that clears warnings about the renaming policy being
1157    * uninitialized from flags.
1158    */
 
1159  99 toggle public void setRenamingPolicy(VariableRenamingPolicy newVariablePolicy,
1160    PropertyRenamingPolicy newPropertyPolicy) {
1161  99 this.variableRenaming = newVariablePolicy;
1162  99 this.propertyRenaming = newPropertyPolicy;
1163    }
1164   
 
1165  0 toggle public void setPropertyAffinity(boolean useAffinity) {
1166  0 this.propertyAffinity = useAffinity;
1167    }
1168   
1169    /** Should shadow outer scope variable name during renaming. */
 
1170  0 toggle public void setShadowVariables(boolean shadow) {
1171  0 this.shadowVariables = shadow;
1172    }
1173   
1174    /**
1175    * If true, flattens multi-level property names on extern types
1176    * (e.g. String$f = x). This should only be used with the typed version of
1177    * the externs files.
1178    */
 
1179  0 toggle public void setCollapsePropertiesOnExternTypes(boolean collapse) {
1180  0 collapsePropertiesOnExternTypes = collapse;
1181    }
1182   
1183    /**
1184    * If true, process goog.testing.ObjectPropertyString instances.
1185    */
 
1186  0 toggle public void setProcessObjectPropertyString(boolean process) {
1187  0 processObjectPropertyString = process;
1188    }
1189   
1190    /**
1191    * @param replaceIdGenerators the replaceIdGenerators to set
1192    */
 
1193  0 toggle public void setReplaceIdGenerators(boolean replaceIdGenerators) {
1194  0 this.replaceIdGenerators = replaceIdGenerators;
1195    }
1196   
1197    /**
1198    * Sets the id generators to replace.
1199    */
 
1200  0 toggle public void setIdGenerators(Set<String> idGenerators) {
1201  0 this.idGenerators = Sets.newHashSet(idGenerators);
1202    }
1203   
1204    /**
1205    * A previous map of ids (serialized to a string by a previous compile).
1206    * This will be used as a hint during the ReplaceIdGenerators pass, which
1207    * will attempt to reuse the same ids.
1208    */
 
1209  0 toggle public void setIdGeneratorsMap(String previousMappings) {
1210  0 this.idGeneratorsMapSerialized = previousMappings;
1211    }
1212   
1213    /**
1214    * Set the function inlining policy for the compiler.
1215    */
 
1216  99 toggle public void setInlineFunctions(Reach reach) {
1217  99 switch (reach) {
1218  19 case ALL:
1219  19 this.inlineFunctions = true;
1220  19 this.inlineLocalFunctions = true;
1221  19 break;
1222  80 case LOCAL_ONLY:
1223  80 this.inlineFunctions = false;
1224  80 this.inlineLocalFunctions = true;
1225  80 break;
1226  0 case NONE:
1227  0 this.inlineFunctions = false;
1228  0 this.inlineLocalFunctions = false;
1229  0 break;
1230  0 default:
1231  0 throw new IllegalStateException("unexpected");
1232    }
1233    }
1234   
1235    /**
1236    * Set the variable inlining policy for the compiler.
1237    */
 
1238  101 toggle public void setInlineVariables(Reach reach) {
1239  101 switch (reach) {
1240  19 case ALL:
1241  19 this.inlineVariables = true;
1242  19 this.inlineLocalVariables = true;
1243  19 break;
1244  82 case LOCAL_ONLY:
1245  82 this.inlineVariables = false;
1246  82 this.inlineLocalVariables = true;
1247  82 break;
1248  0 case NONE:
1249  0 this.inlineVariables = false;
1250  0 this.inlineLocalVariables = false;
1251  0 break;
1252  0 default:
1253  0 throw new IllegalStateException("unexpected");
1254    }
1255    }
1256   
1257    /**
1258    * Set the function inlining policy for the compiler.
1259    */
 
1260  0 toggle public void setInlineProperties(boolean enable) {
1261  0 inlineProperties = enable;
1262    }
1263   
1264    /**
1265    * Set the variable removal policy for the compiler.
1266    */
 
1267  0 toggle @Deprecated
1268    public void setRemoveUnusedVariable(Reach reach) {
1269  0 setRemoveUnusedVariables(reach);
1270    }
1271   
1272    /**
1273    * Set the variable removal policy for the compiler.
1274    */
 
1275  100 toggle public void setRemoveUnusedVariables(Reach reach) {
1276  100 switch (reach) {
1277  19 case ALL:
1278  19 this.removeUnusedVars = true;
1279  19 this.removeUnusedLocalVars = true;
1280  19 break;
1281  81 case LOCAL_ONLY:
1282  81 this.removeUnusedVars = false;
1283  81 this.removeUnusedLocalVars = true;
1284  81 break;
1285  0 case NONE:
1286  0 this.removeUnusedVars = false;
1287  0 this.removeUnusedLocalVars = false;
1288  0 break;
1289  0 default:
1290  0 throw new IllegalStateException("unexpected");
1291    }
1292    }
1293   
1294    /**
1295    * Sets the functions whose debug strings to replace.
1296    */
 
1297  0 toggle public void setReplaceStringsConfiguration(
1298    String placeholderToken, List<String> functionDescriptors) {
1299  0 this.replaceStringsPlaceholderToken = placeholderToken;
1300  0 this.replaceStringsFunctionDescriptions =
1301    Lists.newArrayList(functionDescriptors);
1302    }
1303   
 
1304  0 toggle @Deprecated
1305    public void setRewriteNewDateGoogNow(boolean rewrite) {
1306    }
1307   
 
1308  0 toggle public void setRemoveAbstractMethods(boolean remove) {
1309  0 this.removeAbstractMethods = remove;
1310    }
1311   
 
1312  0 toggle public void setRemoveClosureAsserts(boolean remove) {
1313  0 this.removeClosureAsserts = remove;
1314    }
1315   
1316    /**
1317    * If true, name anonymous functions only. All other passes will be skipped.
1318    */
 
1319  0 toggle public void setNameAnonymousFunctionsOnly(boolean value) {
1320  0 this.nameAnonymousFunctionsOnly = value;
1321    }
1322   
 
1323  0 toggle public void setColorizeErrorOutput(boolean colorizeErrorOutput) {
1324  0 this.colorizeErrorOutput = colorizeErrorOutput;
1325    }
1326   
 
1327  20158 toggle public boolean shouldColorizeErrorOutput() {
1328  20158 return colorizeErrorOutput;
1329    }
1330   
1331    /**
1332    * If true, chain calls to functions that return this.
1333    */
 
1334  0 toggle public void setChainCalls(boolean value) {
1335  0 this.chainCalls = value;
1336    }
1337   
1338    /**
1339    * If true, accept `const' keyword.
1340    */
 
1341  0 toggle public void setAcceptConstKeyword(boolean value) {
1342  0 this.acceptConstKeyword = value;
1343    }
1344   
1345    /**
1346    * Enable run-time type checking, which adds JS type assertions for debugging.
1347    *
1348    * @param logFunction A JS function to be used for logging run-time type
1349    * assertion failures.
1350    */
 
1351  0 toggle public void enableRuntimeTypeCheck(String logFunction) {
1352  0 this.runtimeTypeCheck = true;
1353  0 this.runtimeTypeCheckLogFunction = logFunction;
1354    }
1355   
 
1356  0 toggle public void disableRuntimeTypeCheck() {
1357  0 this.runtimeTypeCheck = false;
1358    }
1359   
 
1360  1 toggle public void setGenerateExports(boolean generateExports) {
1361  1 this.generateExports = generateExports;
1362    }
1363   
 
1364  18427 toggle public void setCodingConvention(CodingConvention codingConvention) {
1365  18427 this.codingConvention = codingConvention;
1366    }
1367   
 
1368  109240 toggle public CodingConvention getCodingConvention() {
1369  109240 return codingConvention;
1370    }
1371   
1372    /**
1373    * Sets dependency options. See the DependencyOptions class for more info.
1374    * This supersedes manageClosureDependencies.
1375    */
 
1376  10 toggle public void setDependencyOptions(DependencyOptions options) {
1377  10 Preconditions.checkNotNull(options);
1378  10 this.dependencyOptions = options;
1379    }
1380   
1381    /**
1382    * Sort inputs by their goog.provide/goog.require calls, and prune inputs
1383    * whose symbols are not required.
1384    */
 
1385  3 toggle public void setManageClosureDependencies(boolean newVal) {
1386  3 dependencyOptions.setDependencySorting(
1387    newVal || dependencyOptions.shouldSortDependencies());
1388  3 dependencyOptions.setDependencyPruning(
1389    newVal || dependencyOptions.shouldPruneDependencies());
1390  3 dependencyOptions.setMoocherDropping(false);
1391  3 manageClosureDependencies = newVal;
1392    }
1393   
1394    /**
1395    * Sort inputs by their goog.provide/goog.require calls.
1396    *
1397    * @param entryPoints Entry points to the program. Must be goog.provide'd
1398    * symbols. Any goog.provide'd symbols that are not a transitive
1399    * dependency of the entry points will be deleted.
1400    * Files without goog.provides, and their dependencies,
1401    * will always be left in.
1402    */
 
1403  2 toggle public void setManageClosureDependencies(List<String> entryPoints) {
1404  2 Preconditions.checkNotNull(entryPoints);
1405  2 setManageClosureDependencies(true);
1406  2 dependencyOptions.setEntryPoints(entryPoints);
1407    }
1408   
1409    /**
1410    * Controls how detailed the compilation summary is. Values:
1411    * 0 (never print summary), 1 (print summary only if there are
1412    * errors or warnings), 2 (print summary if type checking is on,
1413    * see --check_types), 3 (always print summary). The default level
1414    * is 1
1415    */
 
1416  62 toggle public void setSummaryDetailLevel(int summaryDetailLevel) {
1417  62 this.summaryDetailLevel = summaryDetailLevel;
1418    }
1419   
1420    /**
1421    * @deprecated replaced by {@link #setExternExports}
1422    */
 
1423  0 toggle @Deprecated
1424    public void enableExternExports(boolean enabled) {
1425  0 this.externExports = enabled;
1426    }
1427   
 
1428  1 toggle public void setExtraAnnotationNames(Set<String> extraAnnotationNames) {
1429  1 this.extraAnnotationNames = Sets.newHashSet(extraAnnotationNames);
1430    }
1431   
 
1432  229 toggle public boolean isExternExportsEnabled() {
1433  229 return externExports;
1434    }
1435   
1436    /**
1437    * Sets the output charset by name.
1438    */
 
1439  0 toggle public void setOutputCharset(String charsetName) {
1440  0 this.outputCharset = charsetName;
1441    }
1442   
1443    /**
1444    * Gets the output charset as a rich object.
1445    */
 
1446  27639 toggle Charset getOutputCharset() {
1447  27639 return outputCharset == null ? null : Charset.forName(outputCharset);
1448    }
1449   
1450    /**
1451    * Sets how goog.tweak calls are processed.
1452    */
 
1453  63 toggle public void setTweakProcessing(TweakProcessing tweakProcessing) {
1454  63 this.tweakProcessing = tweakProcessing;
1455    }
1456   
 
1457  465 toggle public TweakProcessing getTweakProcessing() {
1458  465 return tweakProcessing;
1459    }
1460   
1461    /**
1462    * Sets how goog.tweak calls are processed.
1463    */
 
1464  23518 toggle public void setLanguageIn(LanguageMode languageIn) {
1465  23518 this.languageIn = languageIn;
1466  23518 this.languageOut = languageIn;
1467    }
1468   
 
1469  40601 toggle public LanguageMode getLanguageIn() {
1470  40601 return languageIn;
1471    }
1472   
 
1473  27256 toggle public LanguageMode getLanguageOut() {
1474  27256 return languageOut;
1475    }
1476   
1477    /**
1478    * Whether to include "undefined" in the default types.
1479    * For example:
1480    * "{Object}" is normally "Object|null" becomes "Object|null|undefined"
1481    * "{?string}" is normally "string|null" becomes "string|null|undefined"
1482    * In either case "!" annotated types excluded both null and undefined.
1483    */
 
1484  0 toggle public void setLooseTypes(boolean looseTypes) {
1485  0 this.looseTypes = looseTypes;
1486    }
1487   
 
1488  27564 toggle @Override
1489    public Object clone() throws CloneNotSupportedException {
1490  27564 CompilerOptions clone = (CompilerOptions) super.clone();
1491    // TODO(bolinfest): Add relevant custom cloning.
1492  27564 return clone;
1493    }
1494   
 
1495  0 toggle public void setAliasTransformationHandler(
1496    AliasTransformationHandler changes) {
1497  0 this.aliasHandler = changes;
1498    }
1499   
 
1500  105 toggle public AliasTransformationHandler getAliasTransformationHandler() {
1501  105 return this.aliasHandler;
1502    }
1503   
1504    /**
1505    * Set a custom handler for warnings and errors.
1506    *
1507    * This is mostly used for piping the warnings and errors to
1508    * a file behind the scenes.
1509    *
1510    * If you want to filter warnings and errors, you should use a WarningsGuard.
1511    *
1512    * If you want to change how warnings and errors are reported to the user,
1513    * you should set a ErrorManager on the Compiler. An ErrorManager is
1514    * intended to summarize the errors for a single compile job.
1515    */
 
1516  0 toggle public void setErrorHandler(ErrorHandler handler) {
1517  0 this.errorHandler = handler;
1518    }
1519   
1520    /**
1521    * If true, enables type inference. If checkTypes is enabled, this flag has
1522    * no effect.
1523    */
 
1524  0 toggle public void setInferTypes(boolean enable) {
1525  0 inferTypes = enable;
1526    }
1527   
1528    /**
1529    * Gets the inferTypes flag. Note that if checkTypes is enabled, this flag
1530    * is ignored when configuring the compiler.
1531    */
 
1532  0 toggle public boolean getInferTypes() {
1533  0 return inferTypes;
1534    }
1535   
1536    /**
1537    * @return Whether assumeStrictThis is set.
1538    */
 
1539  94 toggle public boolean assumeStrictThis() {
1540  94 return assumeStrictThis;
1541    }
1542   
1543    /**
1544    * If true, enables enables additional optimizations.
1545    */
 
1546  0 toggle public void setAssumeStrictThis(boolean enable) {
1547  0 this.assumeStrictThis = enable;
1548    }
1549   
1550    /**
1551    * Sets the list of properties that we report property invalidation errors
1552    * for.
1553    */
 
1554  0 toggle public void setPropertyInvalidationErrors(
1555    Map<String, CheckLevel> propertyInvalidationErrors) {
1556  0 this.propertyInvalidationErrors =
1557    Maps.newHashMap(propertyInvalidationErrors);
1558    }
1559   
 
1560  0 toggle public void setLanguageOut(LanguageMode languageOut) {
1561  0 this.languageOut = languageOut;
1562    }
1563   
 
1564  0 toggle public void setIdeMode(boolean ideMode) {
1565  0 this.ideMode = ideMode;
1566    }
1567   
1568    /**
1569    * Whether to keep internal data structures around after we're
1570    * finished compiling. We do this by default when IDE mode is on.
1571    */
 
1572  0 toggle public void setSaveDataStructures(boolean save) {
1573  0 this.saveDataStructures = save;
1574    }
1575   
 
1576  0 toggle public void setSkipAllPasses(boolean skipAllPasses) {
1577  0 this.skipAllPasses = skipAllPasses;
1578    }
1579   
 
1580  0 toggle public void setDevMode(DevMode devMode) {
1581  0 this.devMode = devMode;
1582    }
1583   
 
1584  0 toggle public void setMessageBundle(MessageBundle messageBundle) {
1585  0 this.messageBundle = messageBundle;
1586    }
1587   
 
1588  0 toggle public void setCheckSymbols(boolean checkSymbols) {
1589  0 this.checkSymbols = checkSymbols;
1590    }
1591   
 
1592  0 toggle public void setCheckSuspiciousCode(boolean checkSuspiciousCode) {
1593  0 this.checkSuspiciousCode = checkSuspiciousCode;
1594    }
1595   
 
1596  0 toggle public void setCheckControlStructures(boolean checkControlStructures) {
1597  0 this.checkControlStructures = checkControlStructures;
1598    }
1599   
 
1600  0 toggle public void setCheckTypes(boolean checkTypes) {
1601  0 this.checkTypes = checkTypes;
1602    }
1603   
 
1604  0 toggle public void setCheckMissingGetCssNameBlacklist(String blackList) {
1605  0 this.checkMissingGetCssNameBlacklist = blackList;
1606    }
1607   
 
1608  0 toggle public void setFoldConstants(boolean foldConstants) {
1609  0 this.foldConstants = foldConstants;
1610    }
1611   
 
1612  0 toggle public void setDeadAssignmentElimination(boolean deadAssignmentElimination) {
1613  0 this.deadAssignmentElimination = deadAssignmentElimination;
1614    }
1615   
 
1616  0 toggle public void setInlineConstantVars(boolean inlineConstantVars) {
1617  0 this.inlineConstantVars = inlineConstantVars;
1618    }
1619   
 
1620  0 toggle public void setInlineFunctions(boolean inlineFunctions) {
1621  0 this.inlineFunctions = inlineFunctions;
1622    }
1623   
 
1624  0 toggle public void setInlineLocalFunctions(boolean inlineLocalFunctions) {
1625  0 this.inlineLocalFunctions = inlineLocalFunctions;
1626    }
1627   
 
1628  0 toggle public void setCrossModuleCodeMotion(boolean crossModuleCodeMotion) {
1629  0 this.crossModuleCodeMotion = crossModuleCodeMotion;
1630    }
1631   
 
1632  0 toggle public void setCoalesceVariableNames(boolean coalesceVariableNames) {
1633  0 this.coalesceVariableNames = coalesceVariableNames;
1634    }
1635   
 
1636  0 toggle public void setCrossModuleMethodMotion(boolean crossModuleMethodMotion) {
1637  0 this.crossModuleMethodMotion = crossModuleMethodMotion;
1638    }
1639   
 
1640  0 toggle public void setInlineGetters(boolean inlineGetters) {
1641  0 this.inlineGetters = inlineGetters;
1642    }
1643   
 
1644  1 toggle public void setInlineVariables(boolean inlineVariables) {
1645  1 this.inlineVariables = inlineVariables;
1646    }
1647   
 
1648  0 toggle public void setInlineLocalVariables(boolean inlineLocalVariables) {
1649  0 this.inlineLocalVariables = inlineLocalVariables;
1650    }
1651   
 
1652  0 toggle public void setFlowSensitiveInlineVariables(boolean enabled) {
1653  0 this.flowSensitiveInlineVariables = enabled;
1654    }
1655   
 
1656  0 toggle public void setSmartNameRemoval(boolean smartNameRemoval) {
1657  0 this.smartNameRemoval = smartNameRemoval;
1658    }
1659   
 
1660  0 toggle public void setRemoveDeadCode(boolean removeDeadCode) {
1661  0 this.removeDeadCode = removeDeadCode;
1662    }
1663   
 
1664  0 toggle public void setExtractPrototypeMemberDeclarations(boolean enabled) {
1665  0 this.extractPrototypeMemberDeclarations = enabled;
1666    }
1667   
 
1668  0 toggle public void setRemoveUnusedPrototypeProperties(boolean enabled) {
1669  0 this.removeUnusedPrototypeProperties = enabled;
1670    }
1671   
 
1672  0 toggle public void setRemoveUnusedPrototypePropertiesInExterns(
1673    boolean enabled) {
1674  0 this.removeUnusedPrototypePropertiesInExterns = enabled;
1675    }
1676   
 
1677  0 toggle public void setRemoveUnusedVars(boolean removeUnusedVars) {
1678  0 this.removeUnusedVars = removeUnusedVars;
1679    }
1680   
 
1681  0 toggle public void setRemoveUnusedLocalVars(boolean removeUnusedLocalVars) {
1682  0 this.removeUnusedLocalVars = removeUnusedLocalVars;
1683    }
1684   
 
1685  1 toggle public void setAliasExternals(boolean aliasExternals) {
1686  1 this.aliasExternals = aliasExternals;
1687    }
1688   
 
1689  0 toggle public void setCollapseVariableDeclarations(boolean enabled) {
1690  0 this.collapseVariableDeclarations = enabled;
1691    }
1692   
 
1693  0 toggle public void setGroupVariableDeclarations(boolean enabled) {
1694  0 this.groupVariableDeclarations = enabled;
1695    }
1696   
 
1697  0 toggle public void setCollapseAnonymousFunctions(boolean enabled) {
1698  0 this.collapseAnonymousFunctions = enabled;
1699    }
1700   
 
1701  0 toggle public void setAliasableStrings(Set<String> aliasableStrings) {
1702  0 this.aliasableStrings = aliasableStrings;
1703    }
1704   
 
1705  0 toggle public void setAliasStringsBlacklist(String aliasStringsBlacklist) {
1706  0 this.aliasStringsBlacklist = aliasStringsBlacklist;
1707    }
1708   
 
1709  0 toggle public void setAliasAllStrings(boolean aliasAllStrings) {
1710  0 this.aliasAllStrings = aliasAllStrings;
1711    }
1712   
 
1713  0 toggle public void setOutputJsStringUsage(boolean outputJsStringUsage) {
1714  0 this.outputJsStringUsage = outputJsStringUsage;
1715    }
1716   
 
1717  0 toggle public void setConvertToDottedProperties(boolean convertToDottedProperties) {
1718  0 this.convertToDottedProperties = convertToDottedProperties;
1719    }
1720   
 
1721  0 toggle public void setRewriteFunctionExpressions(boolean rewriteFunctionExpressions) {
1722  0 this.rewriteFunctionExpressions = rewriteFunctionExpressions;
1723    }
1724   
 
1725  0 toggle public void setOptimizeParameters(boolean optimizeParameters) {
1726  0 this.optimizeParameters = optimizeParameters;
1727    }
1728   
 
1729  0 toggle public void setOptimizeReturns(boolean optimizeReturns) {
1730  0 this.optimizeReturns = optimizeReturns;
1731    }
1732   
 
1733  0 toggle public void setOptimizeCalls(boolean optimizeCalls) {
1734  0 this.optimizeCalls = optimizeCalls;
1735    }
1736   
 
1737  0 toggle public void setOptimizeArgumentsArray(boolean optimizeArgumentsArray) {
1738  0 this.optimizeArgumentsArray = optimizeArgumentsArray;
1739    }
1740   
 
1741  0 toggle public void setVariableRenaming(VariableRenamingPolicy variableRenaming) {
1742  0 this.variableRenaming = variableRenaming;
1743    }
1744   
 
1745  0 toggle public void setPropertyRenaming(PropertyRenamingPolicy propertyRenaming) {
1746  0 this.propertyRenaming = propertyRenaming;
1747    }
1748   
 
1749  0 toggle public void setLabelRenaming(boolean labelRenaming) {
1750  0 this.labelRenaming = labelRenaming;
1751    }
1752   
 
1753  0 toggle public void setReserveRawExports(boolean reserveRawExports) {
1754  0 this.reserveRawExports = reserveRawExports;
1755    }
1756   
 
1757  0 toggle public void setGeneratePseudoNames(boolean generatePseudoNames) {
1758  0 this.generatePseudoNames = generatePseudoNames;
1759    }
1760   
 
1761  0 toggle public void setRenamePrefix(String renamePrefix) {
1762  0 this.renamePrefix = renamePrefix;
1763    }
1764   
 
1765  0 toggle public void setRenamePrefixNamespace(String renamePrefixNamespace) {
1766  0 this.renamePrefixNamespace = renamePrefixNamespace;
1767    }
1768   
 
1769  0 toggle public void setAliasKeywords(boolean aliasKeywords) {
1770  0 this.aliasKeywords = aliasKeywords;
1771    }
1772   
 
1773  0 toggle public void setCollapseProperties(boolean collapseProperties) {
1774  0 this.collapseProperties = collapseProperties;
1775    }
1776   
 
1777  0 toggle public void setDevirtualizePrototypeMethods(boolean devirtualizePrototypeMethods) {
1778  0 this.devirtualizePrototypeMethods = devirtualizePrototypeMethods;
1779    }
1780   
 
1781  0 toggle public void setComputeFunctionSideEffects(boolean computeFunctionSideEffects) {
1782  0 this.computeFunctionSideEffects = computeFunctionSideEffects;
1783    }
1784   
 
1785  0 toggle public void setDebugFunctionSideEffectsPath(String debugFunctionSideEffectsPath) {
1786  0 this.debugFunctionSideEffectsPath = debugFunctionSideEffectsPath;
1787    }
1788   
 
1789  0 toggle public void setDisambiguateProperties(boolean disambiguateProperties) {
1790  0 this.disambiguateProperties = disambiguateProperties;
1791    }
1792   
 
1793  0 toggle public void setAmbiguateProperties(boolean ambiguateProperties) {
1794  0 this.ambiguateProperties = ambiguateProperties;
1795    }
1796   
 
1797  0 toggle public void setAnonymousFunctionNaming(
1798    AnonymousFunctionNamingPolicy anonymousFunctionNaming) {
1799  0 this.anonymousFunctionNaming = anonymousFunctionNaming;
1800    }
1801   
 
1802  0 toggle public void setInputAnonymousFunctionNamingMap(VariableMap inputMap) {
1803  0 this.inputAnonymousFunctionNamingMap = inputMap;
1804    }
1805   
 
1806  0 toggle @Deprecated
1807    public void setInputVariableMapSerialized(byte[] inputVariableMapSerialized)
1808    throws ParseException {
1809  0 this.inputVariableMap = VariableMap.fromBytes(inputVariableMapSerialized);
1810    }
1811   
 
1812  0 toggle public void setInputVariableMap(VariableMap inputVariableMap) {
1813  0 this.inputVariableMap = inputVariableMap;
1814    }
1815   
 
1816  0 toggle @Deprecated
1817    public void setInputPropertyMapSerialized(byte[] inputPropertyMapSerialized)
1818    throws ParseException {
1819  0 this.inputPropertyMap = VariableMap.fromBytes(inputPropertyMapSerialized);
1820    }
1821   
 
1822  0 toggle public void setInputPropertyMap(VariableMap inputPropertyMap) {
1823  0 this.inputPropertyMap = inputPropertyMap;
1824    }
1825   
 
1826  0 toggle public void setExportTestFunctions(boolean exportTestFunctions) {
1827  0 this.exportTestFunctions = exportTestFunctions;
1828    }
1829   
 
1830  0 toggle public void setRuntimeTypeCheck(boolean runtimeTypeCheck) {
1831  0 this.runtimeTypeCheck = runtimeTypeCheck;
1832    }
1833   
 
1834  0 toggle public void setRuntimeTypeCheckLogFunction(String runtimeTypeCheckLogFunction) {
1835  0 this.runtimeTypeCheckLogFunction = runtimeTypeCheckLogFunction;
1836    }
1837   
 
1838  0 toggle public void setSyntheticBlockStartMarker(String syntheticBlockStartMarker) {
1839  0 this.syntheticBlockStartMarker = syntheticBlockStartMarker;
1840    }
1841   
 
1842  0 toggle public void setSyntheticBlockEndMarker(String syntheticBlockEndMarker) {
1843  0 this.syntheticBlockEndMarker = syntheticBlockEndMarker;
1844    }
1845   
 
1846  0 toggle public void setLocale(String locale) {
1847  0 this.locale = locale;
1848    }
1849   
 
1850  0 toggle public void setMarkAsCompiled(boolean markAsCompiled) {
1851  0 this.markAsCompiled = markAsCompiled;
1852    }
1853   
 
1854  0 toggle public void setRemoveTryCatchFinally(boolean removeTryCatchFinally) {
1855  0 this.removeTryCatchFinally = removeTryCatchFinally;
1856    }
1857   
 
1858  35 toggle public void setClosurePass(boolean closurePass) {
1859  35 this.closurePass = closurePass;
1860    }
1861   
 
1862  0 toggle public void setGatherCssNames(boolean gatherCssNames) {
1863  0 this.gatherCssNames = gatherCssNames;
1864    }
1865   
 
1866  0 toggle public void setStripTypes(Set<String> stripTypes) {
1867  0 this.stripTypes = stripTypes;
1868    }
1869   
 
1870  0 toggle public void setStripNameSuffixes(Set<String> stripNameSuffixes) {
1871  0 this.stripNameSuffixes = stripNameSuffixes;
1872    }
1873   
 
1874  0 toggle public void setStripNamePrefixes(Set<String> stripNamePrefixes) {
1875  0 this.stripNamePrefixes = stripNamePrefixes;
1876    }
1877   
 
1878  0 toggle public void setStripTypePrefixes(Set<String> stripTypePrefixes) {
1879  0 this.stripTypePrefixes = stripTypePrefixes;
1880    }
1881   
 
1882  0 toggle public void setCustomPasses(Multimap<CustomPassExecutionTime, CompilerPass> customPasses) {
1883  0 this.customPasses = customPasses;
1884    }
1885   
 
1886  0 toggle public void setMarkNoSideEffectCalls(boolean markNoSideEffectCalls) {
1887  0 this.markNoSideEffectCalls = markNoSideEffectCalls;
1888    }
1889   
 
1890  0 toggle public void setDefineReplacements(Map<String, Object> defineReplacements) {
1891  0 this.defineReplacements = defineReplacements;
1892    }
1893   
 
1894  0 toggle public void setTweakReplacements(Map<String, Object> tweakReplacements) {
1895  0 this.tweakReplacements = tweakReplacements;
1896    }
1897   
 
1898  0 toggle public void setMoveFunctionDeclarations(boolean moveFunctionDeclarations) {
1899  0 this.moveFunctionDeclarations = moveFunctionDeclarations;
1900    }
1901   
 
1902  0 toggle public void setInstrumentationTemplate(String instrumentationTemplate) {
1903  0 this.instrumentationTemplate = instrumentationTemplate;
1904    }
1905   
 
1906  0 toggle public void setRecordFunctionInformation(boolean recordFunctionInformation) {
1907  0 this.recordFunctionInformation = recordFunctionInformation;
1908    }
1909   
 
1910  0 toggle public void setCssRenamingMap(CssRenamingMap cssRenamingMap) {
1911  0 this.cssRenamingMap = cssRenamingMap;
1912    }
1913   
 
1914  0 toggle public void setCssRenamingWhitelist(Set<String> whitelist) {
1915  0 this.cssRenamingWhitelist = whitelist;
1916    }
1917   
 
1918  0 toggle public void setReplaceStringsFunctionDescriptions(List<String> replaceStringsFunctionDescriptions) {
1919  0 this.replaceStringsFunctionDescriptions = replaceStringsFunctionDescriptions;
1920    }
1921   
 
1922  0 toggle public void setReplaceStringsPlaceholderToken(String replaceStringsPlaceholderToken) {
1923  0 this.replaceStringsPlaceholderToken = replaceStringsPlaceholderToken;
1924    }
1925   
 
1926  0 toggle public void setReplaceStringsReservedStrings(Set<String> replaceStringsReservedStrings) {
1927  0 this.replaceStringsReservedStrings = replaceStringsReservedStrings;
1928    }
1929   
 
1930  0 toggle public void setReplaceStringsInputMap(VariableMap serializedMap) {
1931  0 this.replaceStringsInputMap = serializedMap;
1932    }
1933   
 
1934  261 toggle public void setPrettyPrint(boolean prettyPrint) {
1935  261 this.prettyPrint = prettyPrint;
1936    }
1937   
 
1938  55 toggle public void setLineBreak(boolean lineBreak) {
1939  55 this.lineBreak = lineBreak;
1940    }
1941   
 
1942  10 toggle public void setPreferLineBreakAtEndOfFile(boolean lineBreakAtEnd) {
1943  10 this.preferLineBreakAtEndOfFile = lineBreakAtEnd;
1944    }
1945   
 
1946  0 toggle public void setPrintInputDelimiter(boolean printInputDelimiter) {
1947  0 this.printInputDelimiter = printInputDelimiter;
1948    }
1949   
 
1950  0 toggle public void setInputDelimiter(String inputDelimiter) {
1951  0 this.inputDelimiter = inputDelimiter;
1952    }
1953   
 
1954  0 toggle public void setTracer(TracerMode tracer) {
1955  0 this.tracer = tracer;
1956    }
1957   
 
1958  0 toggle public void setErrorFormat(ErrorFormat errorFormat) {
1959  0 this.errorFormat = errorFormat;
1960    }
1961   
 
1962  0 toggle public void setWarningsGuard(ComposeWarningsGuard warningsGuard) {
1963  0 this.warningsGuard = warningsGuard;
1964    }
1965   
 
1966  292 toggle public void setLineLengthThreshold(int lineLengthThreshold) {
1967  292 this.lineLengthThreshold = lineLengthThreshold;
1968    }
1969   
 
1970  0 toggle public void setExternExports(boolean externExports) {
1971  0 this.externExports = externExports;
1972    }
1973   
 
1974  0 toggle public void setExternExportsPath(String externExportsPath) {
1975  0 this.externExportsPath = externExportsPath;
1976    }
1977   
 
1978  0 toggle public void setSourceMapOutputPath(String sourceMapOutputPath) {
1979  0 this.sourceMapOutputPath = sourceMapOutputPath;
1980    }
1981   
 
1982  0 toggle public void setSourceMapDetailLevel(SourceMap.DetailLevel sourceMapDetailLevel) {
1983  0 this.sourceMapDetailLevel = sourceMapDetailLevel;
1984    }
1985   
 
1986  0 toggle public void setSourceMapFormat(SourceMap.Format sourceMapFormat) {
1987  0 this.sourceMapFormat = sourceMapFormat;
1988    }
1989   
 
1990  0 toggle public void setSourceMapLocationMappings(List<SourceMap.LocationMapping> sourceMapLocationMappings) {
1991  0 this.sourceMapLocationMappings = sourceMapLocationMappings;
1992    }
1993   
1994    /**
1995    * Activates transformation of AMD to CommonJS modules.
1996    */
 
1997  0 toggle public void setTransformAMDToCJSModules(boolean transformAMDToCJSModules) {
1998  0 this.transformAMDToCJSModules = transformAMDToCJSModules;
1999    }
2000   
2001    /**
2002    * Rewrites CommonJS modules so that modules can be concatenated together,
2003    * by renaming all globals to avoid conflicting with other modules.
2004    */
 
2005  4 toggle public void setProcessCommonJSModules(boolean processCommonJSModules) {
2006  4 this.processCommonJSModules = processCommonJSModules;
2007    }
2008   
2009    /**
2010    * Sets a path prefix for CommonJS modules.
2011    */
 
2012  0 toggle public void setCommonJSModulePathPrefix(String commonJSModulePathPrefix) {
2013  0 this.commonJSModulePathPrefix = commonJSModulePathPrefix;
2014    }
2015   
2016   
2017    //////////////////////////////////////////////////////////////////////////////
2018    // Enums
2019   
2020    /** When to do the extra sanity checks */
 
2021    public static enum LanguageMode {
2022    /**
2023    * Traditional JavaScript
2024    */
2025    ECMASCRIPT3,
2026   
2027    /**
2028    * Shiny new JavaScript
2029    */
2030    ECMASCRIPT5,
2031   
2032    /**
2033    * Nitpicky, shiny new JavaScript
2034    */
2035    ECMASCRIPT5_STRICT;
2036   
 
2037  62 toggle public static LanguageMode fromString(String value) {
2038  62 if (value.equals("ECMASCRIPT5_STRICT") ||
2039    value.equals("ES5_STRICT")) {
2040  1 return CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT;
2041  61 } else if (value.equals("ECMASCRIPT5") ||
2042    value.equals("ES5")) {
2043  2 return CompilerOptions.LanguageMode.ECMASCRIPT5;
2044  59 } else if (value.equals("ECMASCRIPT3") ||
2045    value.equals("ES3")) {
2046  59 return CompilerOptions.LanguageMode.ECMASCRIPT3;
2047    }
2048  0 return null;
2049    }
2050    }
2051   
2052    /** When to do the extra sanity checks */
 
2053    static enum DevMode {
2054    /**
2055    * Don't do any extra sanity checks.
2056    */
2057    OFF,
2058   
2059    /**
2060    * After the initial parse
2061    */
2062    START,
2063   
2064    /**
2065    * At the start and at the end of all optimizations.
2066    */
2067    START_AND_END,
2068   
2069    /**
2070    * After every pass
2071    */
2072    EVERY_PASS
2073    }
2074   
 
2075    public static enum TracerMode {
2076    ALL, // Collect all timing and size metrics.
2077    RAW_SIZE, // Collect all timing and size metrics, except gzipped size.
2078    TIMING_ONLY, // Collect timing metrics only.
2079    OFF; // Collect no timing and size metrics.
2080   
 
2081  56386 toggle boolean isOn() {
2082  56386 return this != OFF;
2083    }
2084    }
2085   
 
2086    public static enum TweakProcessing {
2087    OFF, // Do not run the ProcessTweaks pass.
2088    CHECK, // Run the pass, but do not strip out the calls.
2089    STRIP; // Strip out all calls to goog.tweak.*.
2090   
 
2091  236 toggle public boolean isOn() {
2092  236 return this != OFF;
2093    }
2094   
 
2095  229 toggle public boolean shouldStrip() {
2096  229 return this == STRIP;
2097    }
2098    }
2099   
2100    /**
2101    * A Role Specific Interface for JS Compiler that represents a data holder
2102    * object which is used to store goog.scope alias code changes to code made
2103    * during a compile. There is no guarantee that individual alias changes are
2104    * invoked in the order they occur during compilation, so implementations
2105    * should not assume any relevance to the order changes arrive.
2106    * <p>
2107    * Calls to the mutators are expected to resolve very quickly, so
2108    * implementations should not perform expensive operations in the mutator
2109    * methods.
2110    *
2111    * @author tylerg@google.com (Tyler Goodwin)
2112    */
 
2113    public interface AliasTransformationHandler {
2114   
2115    /**
2116    * Builds an AliasTransformation implementation and returns it to the
2117    * caller.
2118    * <p>
2119    * Callers are allowed to request multiple AliasTransformation instances for
2120    * the same file, though it is expected that the first and last char values
2121    * for multiple instances will not overlap.
2122    * <p>
2123    * This method is expected to have a side-effect of storing off the created
2124    * AliasTransformation, which guarantees that invokers of this interface
2125    * cannot leak AliasTransformation to this implementation that the
2126    * implementor did not create
2127    *
2128    * @param sourceFile the source file the aliases re contained in.
2129    * @param position the region of the source file associated with the
2130    * goog.scope call. The item of the SourcePosition is the returned
2131    * AliasTransformation
2132    */
2133    public AliasTransformation logAliasTransformation(
2134    String sourceFile, SourcePosition<AliasTransformation> position);
2135    }
2136   
2137    /**
2138    * A Role Specific Interface for the JS Compiler to report aliases used to
2139    * change the code during a compile.
2140    * <p>
2141    * While aliases defined by goog.scope are expected to by only 1 per file, and
2142    * the only top-level structure in the file, this is not enforced.
2143    */
 
2144    public interface AliasTransformation {
2145   
2146    /**
2147    * Adds an alias definition to the AliasTransformation instance.
2148    * <p>
2149    * Last definition for a given alias is kept if an alias is inserted
2150    * multiple times (since this is generally the behavior in JavaScript code).
2151    *
2152    * @param alias the name of the alias.
2153    * @param definition the definition of the alias.
2154    */
2155    void addAlias(String alias, String definition);
2156    }
2157   
2158    /**
2159    * A Null implementation of the CodeChanges interface which performs all
2160    * operations as a No-Op
2161    */
2162    static final AliasTransformationHandler NULL_ALIAS_TRANSFORMATION_HANDLER =
2163    new NullAliasTransformationHandler();
2164   
 
2165    private static class NullAliasTransformationHandler
2166    implements AliasTransformationHandler, Serializable {
2167    private static final long serialVersionUID = 0L;
2168   
2169    private static final AliasTransformation NULL_ALIAS_TRANSFORMATION =
2170    new NullAliasTransformation();
2171   
 
2172  28 toggle @Override
2173    public AliasTransformation logAliasTransformation(
2174    String sourceFile, SourcePosition<AliasTransformation> position) {
2175  28 position.setItem(NULL_ALIAS_TRANSFORMATION);
2176  28 return NULL_ALIAS_TRANSFORMATION;
2177    }
2178   
 
2179    private static class NullAliasTransformation
2180    implements AliasTransformation, Serializable {
2181    private static final long serialVersionUID = 0L;
2182   
 
2183  18 toggle @Override
2184    public void addAlias(String alias, String definition) {
2185    }
2186    }
2187    }
2188    }